import requests
from requests_toolbelt import MultipartEncoder

file_path = "C:\\Users\\summit\\Downloads\\估值导入模版 (1).xlsx"
file_name = '估值导入模版 (1).xlsx'

url = "http://10.1.5.179/bct/margin-service/importPricingResult"
# files = {'file': open(file_path, 'rb')}

data = {
    "params": {
        "valuationDate": "2021-12-16",
        "groupId": "交易环境"}
}

m = MultipartEncoder(
    fields=
    {
        "method": "",
        "params": str({
            "valuationDate": "2021-12-16",
            "groupId": "交易环境"
        }),
        "file":
            (file_name, open(file_path, 'rb'), "multipart/form-data")
    }
)

file = {
    "file": (file_name, open(file_path, 'rb'), "multipart/form-data")
}

data1 = str({
    "params": {
        "valuationDate": "2021-12-16",
        "groupId": "交易环境"
    }
})

headers = {
  #  'Content-Type': m.content_type,
    "Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInJvbGVzIjpbImFkbWluIl0sImlzcyI6InRvbmd5dS50ZWNoIiwiZXhwIjoxNjQ2OTAwNTYwMjgzLCJ1c2VySWQiOiI5YWQ2ZGEzNi04YTExLTRlMzMtODM1Yy0wYmFiY2IwMDgyMzkiLCJpYXQiOjE2MzkxMjQ1NjAyODMsInVzZXJuYW1lIjoiYWRtaW4ifQ.9tw8eI-qU4zf-IXzID1JTjrM3EUvcUUf6Q8qA6YUYA8"
}

response = requests.post(url=url, headers=headers, files=file, data=data1)
print(response.json())

# req = requests.post(url, headers=headers, data=m)
# print(req.text)
